#!/usr/bin/env sh

# 主机目录 => 容器目录
# DB_DATA => /var/lib/mysql
# DB_PATH/log => /var/log/mysql
# DB_PATH => /data

# 加载配置
. /data/install.conf

# 执行 mysql 维护语句
mysql -uroot -p${DB_ROOT_PASSWORD} --default-character-set=utf8mb4 <<EOF
CREATE DATABASE ${DB_DATABASE} DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER '${DB_USERNAME}'@'%' IDENTIFIED WITH mysql_native_password BY '${DB_PASSWORD}';
ALTER USER '${DB_USERNAME}'@'%' IDENTIFIED BY '${DB_PASSWORD}' PASSWORD EXPIRE NEVER;
GRANT ALL PRIVILEGES ON ${DB_DATABASE}.* TO '${DB_USERNAME}'@'%';
FLUSH PRIVILEGES;
EOF